<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="m" uri="/cutm_tags"%>
<head>
<title>编辑方案内容编辑</title>
<style type="text/css">
.btn{background-color: rgb(0, 94, 172); border-color: rgb(184, 212, 232) rgb(18, 70, 128) rgb(18, 70, 128) rgb(184, 212, 232); border-style: solid; border-width: 1px; color: rgb(255, 255, 255); cursor: pointer; font-size: 12px; padding: 2px 15px; text-align: center; margin-left: 5px; font-family: Calibri;}
</style>
<script type="text/javascript" src="<s:url value="/common/scripts/doc.keyEvt.js" />"></script>
<script type="text/javascript" src="<s:url value="/common/scripts/JSON.js" />"></script>
<script type="text/javascript">
$(document).ready(function(){
    function ajaxRequest(){
    	$.urlAjax('solution/EditSolution!ajaxGrenter?macrIds='+getAllSelected(),function(data){
    		alert(data);
    		$('table.schemaBody tbody').append(data);
    	})
    }
	
    $('#save').click(function(){
		var saveObj = {};
		saveObj['solution.id'] = $('#solutionId').val();
		saveObj['items'] = [];
			var order = 0;
			$('table.schemaBody tr.listitem').each(function(){
				var page = {};
				order++;
				page.order = order;
				page.pageNo = $(this).find('td:first input:first').val() || '';
				page.colum = $(this).find('td:eq(1)').text();
				page['editor.id'] = $(this).find('select').val();
				page.items = [];
				var index = 0;
				$(this).find('td:eq(2)>div').each(function(){
					var content = {};
						content.order = index;
						content.page = $(this).find('input:first').val()+'-'+$(this).find('input:eq(1)').val();
						content['manuscript.id'] = $(this).attr('value');
						var desc = $(this).find('input:eq(2)').val();
						content['desc'] = desc==undefined?'':desc;
						page.items.push(content);
						index++;
				});
				saveObj.items.push(page);
		});
		var data = {content:Ext.encode(saveObj)};
		
		$.postAjax('solution/EditSolution!saveSolution',data,function(json){
			if($.trim(json)=='textOK'){
				$.alert('保存成功');
			}else{
				$.alert($.trim(json).substring(4));
			}
		});
    });
    
	$('#addNewPort').click(function(){
		$.fn.jmodal({
	    	title:'未使用稿件',
	    	initWidth : 800,
	    	closeIco : false,
	    	top : 50,
	    	buttonText : '选择完成',
	    	okEvent:ajaxRequest,
	    	buttons : [
	    		'<button style="float:left" class="btn" id="showValid">未使用稿件</button>',
	    		'<button style="float:left" class="btn" id="showPassed">已使用稿件</button>'
	    	],
	    	contentCss : {
                'height': 'auto',
                'background-color': '#F5FFFA',
                'padding': '5px'
	    	},
	        content: '<iframe width="100%" id="showContent" height="350px" frameborder="no" border="0" marginwidth="0" marginheight="0"  allowtransparency="yes" src="<s:url value="/manuscript/ListVaildScript.action" />" ></iframe>'
	     });
    });
    
    $('#showValid').live('click',function(){
    	$('#jmodal-container-title').html('未使用稿件');
    	$('#showContent').attr('src','<s:url value="/manuscript/ListVaildScript.action" />');
    });
    $('#showPassed').live('click',function(){
    	$('#jmodal-container-title').html('已使用稿件');
    	$('#showContent').attr('src','<s:url value="/manuscript/ListVaildScript!used.action" />');
    });
    
    <s:if test="solution.status==3||solution.status==4">
    //禁制编辑状态
    $('table.schemaBody a').each(function(){$(this).attr('style','display:none');});
	$('table.schemaBody input').each(function(){
		$(this).attr('readonly','readonly');
		$(this).css({'border':'none','background' : 'transparent'});		
	});
    </s:if>
    
});

function addSelectedNode2Div(node){
	$('#showSeleced').val(node);
}
function getAllSelected(){
	return $('#showSeleced').val();
}
</script>
</head>
<body>
<h3 class="title">编辑方案内容添加 <m:permiss permiss="SOLUTION_ADD"><s:if test="solution.status lt 3"><m:imgA img="add" id="addNewPort" msg="添加"/></s:if></m:permiss></h3>
<input type="hidden" id="showSeleced">
<s:hidden type="hidden" id="solutionId" name="solution.id" />
<s:property value="renderHtml" escape="false" />

<div class="btnGroup"><input type="button" id="save" value="保存" ></div>
</body>